
##################################
# 🛠 Build Stage: builder
##################################
FROM docker-vercel.17zuoye.net/library/node:22 AS builder

# PROXY FOR GFW
ENV HTTP_PROXY=http://10.8.53.85:8118
ENV HTTPS_PROXY=http://10.8.53.85:8118
ENV NO_PROXY=localhost,127.0.0.1,10.0.0.0/8

# Set the working directory
WORKDIR /app

# Copy lock & manifest files first —> better cache hit
COPY package.json package-lock.json ./

RUN npm ci --verbose --registry https://registry.npmmirror.com

# Copy the rest of the project files AFTER installing dependencies
# to take full advantage of Docker layer caching
COPY . .

# Build the application
RUN npm run build

##################################
# 🚀 Runtime Stage: runner
##################################
FROM docker-vercel.17zuoye.net/library/node:22 AS runner

# Set production environment
ENV NODE_ENV=production

# Set the working directory
WORKDIR /app

# Copy only what's needed to run the production app
COPY --from=builder /app/package.json ./
COPY --from=builder /app/package-lock.json ./
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/next.config.ts ./
COPY --from=builder /app/.env ./

# Expose the application port
EXPOSE 3000

# Start the application
CMD ["npm", "start"]